<?php
namespace app\common\model;
use think\Db;
/**
 * 支付方式模型
 */
class Payment extends Base {
  /**
	 * 获取支付方式种类
	 * $isApp 如果是接口请求,则不返回payConfig数据
	 */
	public function getByGroup($paymentfor = '', $onlineType = -1, $isApp = false){
		$payments = ['0'=>[],'1'=>[]];
		$where = ['paymentStatus'=>1];
		if(in_array($onlineType,[1,0]))$where['isOnline'] = $onlineType;
		$rs = $this->where($where)->where("find_in_set ($paymentfor,paymentFor)")->order('dataSort desc')->select();
		foreach ($rs as $key =>$v){
			if($v['paymentConfig']!='')$v['paymentConfig'] = json_decode($v['paymentConfig'], true);
			if($isApp)unset($v['paymentConfig']);
			$payments[$v['isOnline']][] = $v;
		}
		return $payments;
	}
	/**
	 * 获取支付信息
	 */
	public function getPayment($paymentCode){
		$payment = $this->where("paymentStatus=1 AND paymentCode='$paymentCode' AND isOnline=1")->find();
		if(empty($payment))return [];
		$payConfig = json_decode($payment["paymentConfig"]);
		foreach ($payConfig as $key => $value) {
			$payment[$key] = $value;
		}
		return $payment;
	}
	/**
	 * 获取所有支付方式
	 */
	public function listQuery($isOnline){
		//获取支付信息
		return $this->where(['paymentStatus'=>1,'isOnline'=>$isOnline])->order('paymentId asc')->select();
	}
}